/*
 * @Author: caofujun
 * @Date: 2020-11-13 16:21:15
 * @Description: 业务相关映射的方法
 */
import moment from 'moment'

// 3：正一品 2：一品 1：二品 0：非会员
export const MEMBER_TYPE = {
  'svip': 3,
  'vip': 2,
  'general': 1,
  'nonmember': 0
}

export const MEMBER_TXT = {
  0: '非会员',
  1: '二品姐姐',
  2: '一品姐姐',
  3: '正一品'
}
/**
 * 格式化会员等级选项
 * @param {*} memberTypes  <Array>  3, 2, 1, 0
 * return [{name:'一品姐姐', id: 2}]
 */
export const formatMemberOptions = (memberTypes = [MEMBER_TYPE.svip, MEMBER_TYPE.vip, MEMBER_TYPE.general, MEMBER_TYPE.nonmember]) => {
  if (!memberTypes || Object.prototype.toString.call(memberTypes) !== '[object Array]') {
    throw new Error('memberTypes 必须为数组类型')
  }
  if (memberTypes.length > 0) {
    const temp = []
    memberTypes.map(item => {
      temp.push({ name: MEMBER_TXT[item], id: item })
    })
    return temp
  } else {
    return []
  }
}

// 封禁
export const BAN_TXT = {
  1: '已封禁',
  0: '封禁账号'
}

export const BAN_TYPE = {
  'banned': 1,
  'open': 0
}

//  0-运营，1-用户
export const INVITER_TYPE = {
  admin: 0,
  user: 1
}

// 1-订单返利，2-活动返利，3-邀请的二品活动返利，4-邀请的一品再邀请二品活动返利
export const CPS_TYPE = {
  order: 1,
  activity: 2,
  inviterVip: 3,
  indirectInviterVip: 4
}
// ----提现相关-----
// 1:t提现中、2、提现完成、-1：提现失败、-2：提现失败已退款
export const CASH_STATUS = {
  progress: 1,
  finsh: 2,
  fail: -1,
  failAndRefund: -2
}

export const CASH_NAME = {
  '1': '提现中',
  '2': '提现完成',
  '-1': '提现失败',
  '-2': '提现失败已退款'
}

// 银行类型
export const BANK_CHANNEL_NAME = {
  1: '微信',
  2: '支付宝'
}
export const BANK_CHANNEL_TYPE = {
  wechat: 1,
  alipay: 2
}
// 格式化银行选项
export const formatBankOptions = (o = BANK_CHANNEL_NAME) => {
  const temp = []
  for (const key in o) {
    temp.push({ name: o[key], id: key })
  }
  return temp
}

// ----------------- 退款管理相关 -------------------------------

export const refundTypeMap = {
  6: '退货退款',
  10: '退款不退货',
  11: '仅退款'
}

export const refundStateMap = {
  1: '退款中',
  '-1': '退款失败',
  2: '退款成功'
}

// 退款状态样式
export const statusColor = {
  1: 'statusDots_gray',
  '-1': 'statusDots_red',
  2: 'statusDots_green'
}

export const formatOptions = (O) => {
  const temp = []
  for (const key in O) {
    temp.push({ name: O[key], id: Number(key) })
  }
  return temp
}

// ----- 供应商 ----------

// 供应商管理
export const getSupplierStatusZhCn = (key) => {
  const temp = {
    '0': '已中止',
    '1': '开启'
  }
  return temp[key] ? temp[key] : '未知'
}

// 合同日期
export const getContractExpiresDate = (isLongEffective, expireDate) => {
  let time = null
  if (isLongEffective === 0) {
    moment.locale()
    time = moment(expireDate).format('YYYY-MM-DD')
  }
  const temp = {
    '0': time,
    '1': '长期'
  }
  return temp[isLongEffective] ? temp[isLongEffective] : '未知'
}

// 供应商商户信息类型
export const supplierDtoMap = {
  basePersonInfo: 'basePersonInfo', // 基础信息
  legalPersonInfo: 'legalPersonInfo', // 负责人信息
  supplierAfterSale: 'supplierAfterSale', // 退货地址信息
  supplierEnterPrise: 'supplierEnterPrise', // 企业信息
  supplierSettlement: 'supplierSettlement' // 结算信息
}

// 供应商银行开户

export const supplierBrankAccountStateMap = {
  // 0：未开户，1：开户成功，2：开户失败，3：绑卡成功，4：绑卡失败 5：银行转账失败 6：银行转账成功 7：小额鉴权成功，8：小额鉴权失败
  new: 0,
  acCreateSuccess: 1,
  acCreateFail: 2,
  bindBrankSuccess: 3,
  bindBrankFail: 4,
  transferFail: 5,
  transferSuccess: 6,
  bindBrankAndAuSuccess: 7,
  bindBrankAndAuFail: 8

}

// ----------------------- 订单相关 ----------------------------

// 订单状态：1待支付 2待发货 3待收货 4确认收货 5退款中 6退款退货 7订单过期 8订单挂起 9取消订单 10退款但不退货 11仅退款
export const orderState = {
  noPayment: 1,
  waitDeliver: 2,
  waitDelivery: 3,
  complete: 4,
  onRefund: 5,
  refundReturn: 6,
  cancelOrder: 9,
  refundNoSaleReturn: 10,
  onlyRerund: 11
}

export const orderStateName = {
  1: '待支付', 2: '待发货', 3: '待收货', 4: '确认收货', 5: '退款中', 6: '退款退货', 7: '订单过期',
  8: '订单挂起',
  9: '取消订单', 10: '退款但不退货', 11: '仅退款'
}

export const paymentModeMap = {
  2: '支付宝',
  22: '微信',
  40: '微信代付',
  0: '优惠抵扣'
}
